def max_subarray(nums):
    current = nums[0]
    max_sum = nums[0]
    for x in nums[1:]:
        current = max(x, current + x)
        max_sum = max(max_sum, current)
    return max_sum
line = input("请输入data：\n").strip()
arr = list(map(int, line.split()))
i = 0
while i < len(arr):
    n = arr[i]
    if n == 0:
        break
    nums = arr[i+1 : i+1+n]
    ans = max_subarray(nums)
    print(ans)
    i = i + 1 + n
